package cn.shadow.module.scene;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.Data;

@Data
public class ViewObj {
    private long id;
    private int viewId;
    private int x;
    private int y;
    protected ViewGrid viewGrid;
    private ByteBuf removeMsg;

    public ViewObj(long id, int viewId) {
        this.id = id;
        this.viewId = viewId;
        this.removeMsg = Unpooled.buffer(10);
    }


    public ViewObj(long id) {
        this(id, 0);
    }

    public void setViewGrid(ViewGrid viewGrid) {
        this.viewGrid = viewGrid;
    }


    /**
     * 是否视野发生改变
     */
    public boolean isViewChanged(int curX, int curY) {
        if (x == curX && y == curY) {
            return false;
        }
        this.x = curX;
        this.y = curY;
        return true;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public long getId() {
        return id;
    }

    public int getViewId() {
        return viewId;
    }

    /**
     * 返回当前所在格子
     */
    public ViewGrid getViewGrid() {
        return viewGrid;
    }

    /**
     * 是否可以看到自己
     */
    public boolean isHeroCanSeeMe(HeroViewObj heroViewObj) {
        return true;
    }

    /**
     * @param sender 通知的玩家
     */
    public void doRemoveFromHero(HeroViewObj sender) {
        System.out.println(String.format("玩家[%s]移除玩家[%s]",sender.getId(),this.id));
//        sender.sendMessage(removeMsg); //发送当前玩家移除消息
    }


}
